package cn.tedu.spring.life;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @author tune_the last
 * @date 2025/11/7 - 9:29
 *  Bean对象的生命周期：
 *      1.实例化：无参构造
 *      2.属性赋值：set方法
 *      3.初始化：@PostConstruct
 *      4.开发者使用
 *      5.销毁：@PreDestroy
 */
@Component
public class DBConnect {
    private String username;
    private DBao dBao;

    public DBConnect(){
        System.out.println("1.调用无参构造实例化");
    }

    @Autowired
    public DBConnect(DBao dBao){
        this.dBao = dBao;
        System.out.println("1.调用有参构造实例化****");
    }
    @Value("30")
    public void setUsername(String username) {
        this.username = username;
        System.out.println("2.调用set方法属性");
    }



    @PostConstruct
    public void init(){
        System.out.println("3.执行生命周期初始化的方法");
    }

    @PreDestroy
    public void destroy(){
        System.out.println("5.执行生命周期销毁的方法");
    }
}
